from collections import defaultdict
from operator import index
import os
import requests
import json

from requests.packages import urllib3
urllib3.disable_warnings()


ddiaPath = "./DDIA-Reading-Notes/"
targetPath = "docs/ddia/"

if not os.path.exists(targetPath):
    os.mkdir(targetPath)

titles = [
"第一章：可靠性，可扩展性，可维护性",
"第二章：数据模型与查询语言",
"第三章：存储与检索",
"第四章：数据编码与演化",
"第五章：数据复制",
"第六章：分区",
"第七章：事务",
"第八章：分布式系统的挑战",
"第九章：一致性与共识",
"第十章：批处理",
"第十一章：流处理",
"第十二章：数据系统的未来",
]

header = """---
icon: page
title: {}
# 设置作者
author: 负雪明烛
# 设置写作时间
date: 2022-04-28
category:
  - 读书笔记
tag:
  - 数据密集型应用系统设计
  - DDIA
  - 大数据
---

"""


articles = os.listdir(ddiaPath)
for article in articles:
    if article.startswith("."):
        continue
    print(article)
    if article == "README.md":
        title = "一本神书：《数据密集型应用系统设计》"
    else:
        chapter = int(article.replace("chapter", "").replace(".md", ""))
        title = titles[chapter - 1]
    with open(ddiaPath + article) as start:
        with open(targetPath + article, "w") as end:
            end.writelines(header.format(title))
            end.writelines(start.readlines())


